<?php

/**
 * 首页控制器
 * @author yupoxiong<i@yupoxiong.com>
 */

declare(strict_types=1);

namespace app\admin\controller;

use app\common\model\Adjust;
use app\common\model\User;
use Exception;
use think\Request;

class IndexController extends AdminBaseController
{
    /**
     * 后台首页
     * @return string
     * @throws Exception
     */
    public function index(Request $request): string
    {
        $adid = $request->get('adid',0);
        $del = $request->get('del', 0);
        $this->assign('del');
        $this->assign('adid', $adid);
        if ($adid) {
            if ($del) {
                User::destroy(['adid' => $adid], true);
                Adjust::destroy(['adid' => $adid], true);
                echo ' 删除成功';
                echo '<br/>';
                echo '<a href="/admin/index/index.html?adid='.$adid.'">查询</a>';
                die;
            } else {
                $user_data =User::where('adid', $adid)->select();
                $adjust_data = Adjust::where('adid', $adid)->select() ;
                echo 'user:'.count($user_data);
                echo '<br/>';
                echo 'adjust:'.count($adjust_data);
                echo '<br/>';
                echo '<a href="/admin/index/index.html?adid='.$adid.'&del=1">删除</a>';
                die;
            }
        }
        return  $this->fetch();
    }
}
